package com.xiyan.mocklocation.utils;

import com.alibaba.fastjson2.JSONObject;
import com.xiyan.mocklocation.domain.PersonVO;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomDataUtils {
    private static final int maxNum = 10000;
    public static final int cardBasicId = 1000000000;
    public static final int personBasicId = 2000000000;
    private static final String personBasicName = "王-";
    private static final BigDecimal maxLongitude = new BigDecimal("107.73644145055464");
    private static final BigDecimal maxLatitude = new BigDecimal("31.53748722716472");
    private static final BigDecimal minLongitude =new BigDecimal("107.71705427166556");
    private static final BigDecimal minLatitude = new BigDecimal("31.52457347592255");
    private static final String layerId = "dazhou";

    private static BigDecimal getRandomLongitude(BigDecimal lowerBound, BigDecimal upperBound) {
        // 生成一个随机的小数
        Random random = new Random();
        double randomDouble = lowerBound.doubleValue() + random.nextDouble() * (upperBound.doubleValue() - lowerBound.doubleValue());
        // 将随机小数转换为BigDecimal，并指定舍入模式以保持精度
        return new BigDecimal(randomDouble).setScale(14, RoundingMode.HALF_UP);
    }

    public static List<Long> getCardId() {
        List<Long> cardIdList = new ArrayList<>();
        for (int i = 1; i <= maxNum; i++) {
            long cardId = cardBasicId + i;
            cardIdList.add(cardId);
        }
        return cardIdList;
    }

    private static List<Long> getPersonId() {
        List<Long> personIdList = new ArrayList<>();
        for (int i = 1; i <= maxNum; i++) {
            long personId = personBasicId + i;
            personIdList.add(personId);
        }
        return personIdList;
    }

    public static List<PersonVO> getPersonVO() {
        List<PersonVO> personVOList = new ArrayList<>();
        List<Long> personIdList = getPersonId();
        int size=personIdList.size();
        for (int i=0;i<size;i++
        ) {
            Long personId = personIdList.get(i);
            PersonVO personVO = PersonVO.builder().personId(personId).personName(personBasicName + (i+1))
                    .cardId(personId - cardBasicId).layerId(layerId)
                    .longitude(getRandomLongitude(minLongitude,maxLongitude))
                    .latitude(getRandomLongitude(minLatitude,maxLatitude))
                    .build();
            personVOList.add(personVO);
        }
        return personVOList;
    }

    public static void main(String[] args) {
        System.out.println(JSONObject.toJSONString(getPersonVO()));
    }
}
